#!/usr/bin/env python

# python-resmon - Python tools for Resmon monitoring and the Circonus API
# Copyright (c) 2010 Crown coypright
# 
# This file is part of python-resmon.
# 
# python-resmon is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# python-resmon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with python-resmon.  If not, see <http://www.gnu.org/licenses/>.


"""Start a webservice daemon to report current alert status"""

import os
from optparse import OptionParser

from checker.webservice import start_server, StatusService, Server, StatusRequestHandler

parser = OptionParser()
parser.add_option('-p', '--port', help="Port to listen on", default=80, type='int')
parser.add_option('-d', '--daemonize', help="Run as a daemon", action='store_true')

options, args = parser.parse_args()

if options.daemonize:
    from daemon import DaemonContext

    with DaemonContext(working_directory=os.getcwd()):
        start_server(port=options.port)
else:
        start_server(port=options.port)
